﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity;
using System.Linq;

namespace Asp.Models
{
    public class Movie
    {
        public int ID { get; set; }


        [StringLength(60,MinimumLength = 3)]
        public string Title { get; set; }

        [Display(Name="Release Date")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString ="{0:yyyy-MM-dd}",ApplyFormatInEditMode =true)]
        public DateTime ReleaseDate { get; set; }


        [RegularExpression(@"^[A-Z]+[a-zA-Z''-'\s]*$")]
        [Required]
        [StringLength(30)]
        public string Genre { get; set; }

        [Range(1,100)]
        [DataType(DataType.Currency)]
        public decimal Price { get; set; }
    }

    public interface IMovieDb : IDisposable
    {
        IQueryable<T> Query<T>() where T : class;
    }

    public class MovieDBContext : DbContext,IMovieDb
    {
        public DbSet<Movie> Movies { get; set; }

        IQueryable<T> IMovieDb.Query<T>()
        {
            return Set<T>();
        }
    }
}